#!/usr/bin/node

const log = console.log;
const koa = require('koa');
const cost = require('./lib/task.js');

let app = new koa();

//加载使用中间件

//M-logger
app.use(async (ctx, next){
  const start = Date.now();
  await next();
  const end = Date.now();
  ctx.cost = end-start;

  log(`${ctx.method} ${ctx.url}`);
      
})

//M-hello
app.use((ctx,next)=>{
  //requset parse
  //make response
  
  ctx.body='hello koa, task cost: '+ await task()+'ms';
});



app.listen(9000);

log('hello world');

